<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
    
    <head>
        <meta charset="UTF-8">
        <title>后台模板SpringbootDemo版本</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="/static/css/font.css">
        <link rel="stylesheet" href="/static/css/xadmin.css">
        <script src="/static/js/jquery.min.js" charset="utf-8"></script>
        <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/js/xadmin.js"></script>
    </head>

    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">系统管理</a>
                <a>
                    <cite>菜单管理</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">

                            <hr>

                        </div>
                        <div class="layui-card-header">
                            <div class="layui-btn" onclick="xadmin.open('添加根节点菜单','/system/menu/0/0')">增加根节点菜单</div>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                              <thead>
                                <tr>
                                  <th>菜单名</th>
                                  <th >请求Url</th>
                                  <th >操作</th>
                              </thead>
                              <tbody class="x-cate">
                                <tr th:each="menu:${menuList}" th:attr="cate-id=${menu.id},fid=${menu.parentid} ">
                                  <td th:if="${menu.parentid == 0}">
                                      <i class="layui-icon x-show" status='true'>&#xe623;</i>
                                      <span th:text="${menu.menuName}"></span>
                                  </td>
                                  <td th:if="${menu.parentid != 0}">
                                      &nbsp;&nbsp;&nbsp;&nbsp;
                                      <span th:text="${menu.menuName}"></span>
                                  </td>
                                  <td th:text="${menu.menuUrl}"></td>
                                  <td class="td-manage">
                                    <button th:if="${menu.parentid != 0}" class="layui-btn layui-btn layui-btn-xs" th:onclick="${'xadmin.open(''编辑'',''/system/menu/'+menu.id+'/1'')'}"  ><i class="layui-icon">&#xe642;</i>编辑</button>
                                    <button th:if="${menu.parentid == 0}" class="layui-btn layui-btn-warm layui-btn-xs"  th:onclick="${'xadmin.open(''编辑'',''/system/menu/'+menu.id+'/0'')'}" ><i class="layui-icon">&#xe642;</i>添加子菜单</button>
                                    <button th:if="${menu.parentid != 0}" class="layui-btn-danger layui-btn layui-btn-xs"  th:onclick="${'member_del(''this'','''+menu.id+''')'}" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                  </td>
                                </tr>
                              </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>
          layui.use(['form'], function(){
            form = layui.form;

          });

          // 分类展开收起的分类的逻辑
          // 
          $(function(){
            $("tbody.x-cate tr[fid!='0']").hide();
            // 栏目多级显示效果
            $('.x-show').click(function () {
                if($(this).attr('status')=='true'){
                    $(this).html('&#xe625;'); 
                    $(this).attr('status','false');
                    cateId = $(this).parents('tr').attr('cate-id');
                    $("tbody tr[fid="+cateId+"]").show();
               }else{
                    cateIds = [];
                    $(this).html('&#xe623;');
                    $(this).attr('status','true');
                    cateId = $(this).parents('tr').attr('cate-id');
                    getCateId(cateId);
                    for (var i in cateIds) {
                        $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
                    }
               }
            })
          })

          var cateIds = [];
          function getCateId(cateId) {
              $("tbody tr[fid="+cateId+"]").each(function(index, el) {
                  id = $(el).attr('cate-id');
                  cateIds.push(id);
                  getCateId(id);
              });
          }

          function member_del(obj,id){
              layer.confirm('确认要删除吗？',function(index){

                  $.ajax({
                      type : "DELETE",
                      url : "/system/menu/"+id,
                      dataType : "json",
                      data : {
                      },
                      success : function(e) {
                          if(e.code == 0){
                              layer.alert("删除成功",{icon:6},function(){
                                  //关闭当前frame
                                  xadmin.close();
                                  // 可以对父窗口进行刷新
                                  xadmin.father_reload();
                              });

                          }
                      }
                  });

              });
          }
   
        </script>
    </body>
</html>
